<template>
	<div class="app-container">
		<div class="head-container">
			<div v-if="crud.props.searchToggle">
				<el-input v-model="query.name" clearable size="small" placeholder="全表模糊搜索" style="width: 200px;"
					class="filter-item" @keyup.enter.native="crud.toQuery" />
				<rrOperation />
			</div>
			<crudOperation :permission="permission" />
		</div>

		<!-- 表单 -->
		<el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU"
			:visible.sync="crud.status.cu > 0" :title="crud.status.title" width="680px">
			<el-form ref="form" :model="form" label-width="120px">
				<el-form-item label="活动名称">
					<el-input v-model="form.name" />
				</el-form-item>
				<el-form-item label="活动规则">
					<!-- <div ref="editor" v-model="form.rule" class="editor"></div> -->
					<el-input v-model="form.rule" type="textarea" :rows="4" />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="text" @click="crud.cancelCU">取消</el-button>
				<el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
			</div>
		</el-dialog>

		<!--表格渲染-->
		<el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;"
			@selection-change="crud.selectionChangeHandler">
			<el-table-column type="selection" width="55" />
			<el-table-column prop="name" align="center" label="活动名称" />
			<el-table-column prop="rule" align="center" label="活动规则" />
			<el-table-column v-if="checkPer(['admin','menu:edit','menu:del'])" align="center" label="操作" width="150px"
				fixed="right">
				<template slot-scope="scope">
					<udOperation :data="scope.row" :permission="permission" msg="确定删除吗，此操作不能撤销！" />
				</template>
			</el-table-column>
		</el-table>
		<!--分页组件-->
		<pagination />
	</div>
</template>
<script>
	// import E from 'wangeditor'
	import crudActivity from '@/api/finace_taxation/activity.js'
	import CRUD, {
		presenter,
		header,
		form,
		crud
	} from '@crud/crud'
	import rrOperation from '@crud/RR.operation'
	import crudOperation from '@crud/CRUD.operation'
	import pagination from '@crud/Pagination'
	import udOperation from '@crud/UD.operation'

	// crud交由presenter持有
	const defaultForm = {
		name: null,
		rule: null
	}

	export default {
		name: 'Activity',
		components: {
			pagination,
			crudOperation,
			rrOperation,
			udOperation
		},
		cruds() {
			return CRUD({
				url: 'api/ft/ftActivity',
				title: '活动管理',
				crudMethod: {
					...crudActivity
				}
			})
		},
		mixins: [presenter(), header(), form(defaultForm), crud()],
		data() {
			return {
				delLoading: false,
				permission: {
					add: ['admin', 'ftActivity:add'],
					edit: ['admin', 'ftActivity:edit'],
					del: ['admin', 'ftActivity:del']
				},
				cityList: []
			}
		},
		created() {
			this.crud.optShow = {
				add: true,
				reset: true
			}
		},
		methods: {

		}
		// mounted() {
		// 	const _this = this
		// 	var editor = new E(this.$refs.editor)
		// 	// 自定义菜单配置
		// 	editor.customConfig.zIndex = 10
		// 	// 文件上传
		// 	editor.customConfig.customUploadImg = function(files, insert) {
		// 		// files 是 input 中选中的文件列表
		// 		// insert 是获取图片 url 后，插入到编辑器的方法
		// 		files.forEach(image => {
		// 			upload(_this.imagesUploadApi, image).then(res => {
		// 				const data = res.data
		// 				const url = _this.baseApi + '/file/' + data.type + '/' + data.realName
		// 				insert(url)
		// 			})
		// 		})
		// 	}
		// 	editor.create()
		// 	// 初始化数据
		// 	editor.txt.html(this.form.rule)
		// }
	}
</script>
